<?php

require_once '../common/table.php';

function cmp($a, $b)
{
    return ($a["diff"] < $b["diff"]);
}

$users = array();

$lines1 = file('00data.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$lines2 = file('data.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

$total_inf = 0;

for($i = 0; $i < count($lines2); ++$i) {

	$a = explode(',', $lines1[$i]);
	$b = explode(',', $lines2[$i]);

	if ($b[5] == $a[5]) {
		continue;
	}

	$detail = getRank($b[5]);
	$inf = (($detail[0]-1)/20 + 0.3) * (($b[4] / 10) + 40);

	$diff = ($b[5] - $a[5]) * 10;
	$fights = $diff / ($inf * 2);
	$total_inf += $diff;

	if ($fights < 1) {
		$fights = 1;
	}
	
	$user[] = array('name' => $b[1], 'diff' => $diff, 'fights' => $fights);
}

usort($user, "cmp");

echo "total_inf = $total_inf\r\n\r\n";

foreach($user as $key => $row) {
	printf("<%d> [b]%s[/b], %d, %d\r\n", $key+1,
					$row["name"],
					$row["diff"], 
					$row["fights"]
				);
}

?>
